//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package 力扣.题库.未分类;

public class demo_704 {
    public demo_704() {
    }

    public static void main(String[] args) {
        int[] nums = new int[]{-1, 0, 3, 5, 9, 12};
        int target = 3;
        System.out.println(search(nums, target));
    }

    public static int search(int[] nums, int target) {
        int left = 0;
        int right = nums.length - 1;
        int min = nums.length / 2;

        while(left <= right) {
            if (nums[min] < target) {
                left = min + 1;
                min = (left + right) / 2;
            } else {
                if (nums[min] <= target) {
                    return min;
                }

                right = min - 1;
                min = (left + right) / 2;
            }
        }

        return -1;
    }

    public static int search2(int[] nums, int target) {
        int left = 0;
        int right = nums.length;

        while(left < right) {
            int min = (left + right) / 2;
            if (nums[min] < target) {
                left = min + 1;
            } else {
                if (nums[min] <= target) {
                    return min;
                }

                right = min;
            }
        }

        return -1;
    }
}
